<?php

class UserModel extends CommonModel
{
    public function getUserInfo($id)
    {
        if (empty($id)) {
            return false;
        }

        $where = array('id' => $id, 'status' => 1);
        return $this->where($where)->find();
    }

    public function getUserInfoWithUnionID($unionID)
    {
        if (empty($unionID)) {
            return NULL;
        }

        $where = array('identify' => $unionID, 'status' => 1);
        $record = $this->where($where)->find();
        if (empty($record)) {
            return NULL;
        }

        $now = date('Y-m-d h:i:s');
        $this->where($where)->update(array('last_time' => $now, 'update_time' => $now));
        return $record;
    }

    public function addUser($unionID)
    {
        $data = array(
            'identify' => $unionID, 
            'status' => 1,
            'is_follow' => 0,
            'last_time' => date('Y-m-d h:i:s'),
            'create_time' => date('Y-m-d h:i:s')
        );

        $id = $this->addRecord($data);
        return array('id' => $id);
    }
}
